﻿using LS.FrmUI.Dal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LS.FrmUI
{
    public partial class FrmUserManger : Form
    {
        public FrmUserManger()
        {
            InitializeComponent();
        }
        UserInfoDal dal = new UserInfoDal();

        private void FrmUserManger_Load(object sender, EventArgs e)
        {
            DataTable dt = dal.GetAllUser();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    cboUser.Items.Add(Convert.ToString(dr["UserName"]));
                }
                cboUser.SelectedIndex = 0;
            }
        }

        private void cboUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtPWD.Text= dal.GetPwdByUserName(cboUser.Text);
        }

        private void btnModifyPwd_Click(object sender, EventArgs e)
        {
               if (cboUser.Text == "" || string.IsNullOrEmpty(txtPWD.Text))
            {
                MessageBox.Show("请选择用户并输入有效密码");
                return;
            }
              bool b= dal.UpdateUserPwd(cboUser.Text, txtPWD.Text);
              if (b)
              {
                  MessageBox.Show("修改成功");
              }
              else
              {
                  MessageBox.Show("修改失败。.");
              }
        }
    }
}




